dc_loc <- geocode("Washington, D.C.")
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Washington,+D.C.&key=xxx-EvQ
dc_map <- qmap(c(lon=dc_loc$lon, lat=dc_loc$lat), source="google", zoom=12)
## Source : https://maps.googleapis.com/maps/api/staticmap?center=38.907192,-77.036871&zoom=12&size=640x640&scale=2&maptype=terrain&language=en-EN&key=xxx-EvQ
dc_map

ph_loc <- geocode("Philadelphia")
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Philadelphia&key=xxx-EvQ
ph_map <- qmap(c(lon=ph_loc$lon, lat=ph_loc$lat), source="google", zoom=12)
## Source : https://maps.googleapis.com/maps/api/staticmap?center=39.952584,-75.165222&zoom=12&size=640x640&scale=2&maptype=terrain&language=en-EN&key=xxx-EvQ
ph_map

ny_loc <- geocode("New York")
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=New+York&key=xxx-EvQ
ny_map <- qmap(c(lon=ny_loc$lon, lat=ny_loc$lat), source="google", zoom=12)
## Source : https://maps.googleapis.com/maps/api/staticmap?center=40.712775,-74.005973&zoom=12&size=640x640&scale=2&maptype=terrain&language=en-EN&key=xxx-EvQ
ny_map

# lv_loc <- geocode("Clark County, N.V.")
# lv_map <- qmap(c(lon=lv_loc$lon, lat=lv_loc$lat), source="google", zoom=12)
# lv_map
world <- ne_countries(scale = "medium", returnclass = "sf")
class(world)
## [1] "sf" "data.frame"
ggplot(data = world) +
geom_sf(color = "black", fill = "lightgreen") +
xlab("Longitude") + ylab("Latitude") +
ggtitle("World map", subtitle = paste0("(", length(unique(world$NAME)), " countries)"))

ggplot(data = world) +
geom_sf(aes(fill = pop_est)) +
scale_fill_viridis_c(option = "plasma", trans = "sqrt")

world_points<- st_centroid(world)
world_points <- cbind(world, st_coordinates(st_centroid(world$geometry)))
sites <- data.frame(longitude = c(-80.144005, -80.109), latitude = c(26.479005, 26.83))
sites <- st_as_sf(sites, coords = c("longitude", "latitude"), crs = 4326, agr = "constant")
ggplot(data = world) +
geom_sf(fill= "antiquewhite") +
geom_sf(data = sites, size = 4, shape = 23, fill = "darkred") +
geom_text(data= world_points,aes(x=X, y=Y, label=name),
color = "darkblue", fontface = "bold", check_overlap = FALSE) +
annotate(geom = "text", x = -90, y = 26, label = "Gulf of Mexico",
fontface = "italic", color = "grey22", size = 6) +
annotation_scale(location = "bl", width_hint = 0.5) +
annotation_north_arrow(location = "bl", which_north = "true",
pad_x = unit(0.75, "in"), pad_y = unit(0.5, "in"),
style = north_arrow_fancy_orienteering) +
coord_sf(xlim = c(-102.15, -74.12), ylim = c(7.65, 33.97), expand = FALSE) +
xlab("Longitude") +
ylab("Latitude") +
ggtitle("Map of the Gulf of Mexico and the Caribbean Sea") +
theme(panel.grid.major = element_line(color = gray(.5), linetype = "dashed", size = 0.5),
panel.background = element_rect(fill = "aliceblue"))
## Scale on map varies by more than 10%, scale bar may be inaccurate

states <- st_as_sf(map("state", plot = FALSE, fill = TRUE))
states <- cbind(states, st_coordinates(st_centroid(states)))
states$ID <- toTitleCase(states$ID)
head(states)
## Simple feature collection with 6 features and 3 fields
## geometry type: MULTIPOLYGON
## dimension: XY
## bbox: xmin: -124.3834 ymin: 30.24071 xmax: -71.78015 ymax: 42.04937
## epsg (SRID): 4326
## proj4string: +proj=longlat +datum=WGS84 +no_defs
## ID X Y geometry
## 1 Alabama -86.83042 32.80316 MULTIPOLYGON (((-87.46201 3...
## 2 Arizona -111.66786 34.30060 MULTIPOLYGON (((-114.6374 3...
## 3 Arkansas -92.44013 34.90418 MULTIPOLYGON (((-94.05103 3...
## 4 California -119.60154 37.26901 MULTIPOLYGON (((-120.006 42...
## 5 Colorado -105.55251 38.99797 MULTIPOLYGON (((-102.0552 4...
## 6 Connecticut -72.72598 41.62566 MULTIPOLYGON (((-73.49902 4...
states$nudge_y <- -1
states$nudge_y[states$ID == "Florida"] <- 0.5
states$nudge_y[states$ID == "South Carolina"] <- -1.5
counties <- st_as_sf(map("county", plot = FALSE, fill = TRUE))
counties$area <- as.numeric(st_area(counties))
ggplot(data = world) +
geom_sf() +
geom_sf(data = states, fill = NA) +
geom_sf(data = counties, fill = NA, color = gray(.5)) +
geom_label(data = states, aes(X, Y, label = ID), size = 5, fontface = "bold",
nudge_y = states$nudge_y) +
coord_sf(xlim = c(-88, -78), ylim = c(24.5, 33), expand = FALSE)
